//
//  ViewController.h
//  BTDemo
//
//  Created by Avery on 14-8-20.
//  Copyright (c) 2014年 Alvin. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "LMComBoxView.h"

#pragma pack(1)

/* iTrainer 设备测试常量 */
#define  CMD_GET_ANA_STATE    21u    //<! Request : Get Analyser Mode
#define     CMD_SET_TIME            60u                         //<! Sets the SMCD time to the PC time
#define     CMD_SET_ANA_MODE        20u                         //<! Set Analyser Mode
#define     CMD_SET_CLUB            61u                         //<! Sets the specs for the current club

typedef struct
{
    char                  Command;                                //!< CMD_DIRECTORY
    char                 Dummy;
    char                  Model[16];                              //<! Club model
    char                  Type[16];                               //<! Club type
    char                  Key[16];                  //<! Club key (within club def ini)
    char                  Name[16];                               //<! Name of the club
    float               ShaftLength;                            //<! Shaft length in cm
    float               LieAngle;                               //<! Shaft lie in radians
    float               LoftAngle;                              //<! Shaft loft in radians
    float               TorqueAngle;                            //<! Torque (radians)
    float               HeadMass;                               //<! Head Mass in grams
    unsigned short         Checksum;                               //<! 16bit checksum
} CMD_CLUB_SPEC_T;

typedef enum
{
    ANA_MODE_NONE,                                              //<! Stop analyser
    ANA_MODE_PITCH,                                             //<! Pitch
    ANA_MODE_BEARING,                                           //<! Raised + Bearing
    ANA_MODE_ADDRESS,                                           //<! Address
    ANA_MODE_ALIGN,                                             //<! Club face alignment
    ANA_MODE_PRESS,                                             //<! Press Angle
    ANA_MODE_PLANE,                                             //<! Swing Plane
    ANA_MODE_SWING,                                             //<! Full Swing capture
    ANA_MODE_FREE,                                              //<! Free Swing mode
    ANA_MODE_CAPTURE,                                           // Full Swing Capture
} ANA_MODE_T;


typedef struct
{
    float   M11, M12, M13;
    float   M21, M22, M23;
    float   M31, M32, M33;
} FloatMatrix3x3_T;


//<! Response
typedef struct
{
    char                Command;    //!< Original Command
    char                Dummy;
    unsigned short      Result;     //!< Command result
    unsigned short      Checksum;   //!< 16bit checksum
} RSP_GENERAL_T;

typedef struct
{
    unsigned char                  Command;                                /* CMD_SET_TIME */
    unsigned char                  Dummy;                                  /* Padding */
    time_t              Seconds;                                /* Seconds since 1/1/1970 */
    unsigned short                 Checksum;                               /* 16-bit Checksum */
} CMD_SETTIME_T;

typedef struct
{
    unsigned short                 PlaneCone       : 1;                    // Check plane within limits
    unsigned short                 UseIndicators   : 1;                    // Enable LED indicators
    unsigned short                 PuttingMode     : 1;                    // Putting mode if true
    unsigned short                 PlaneSweep      : 1;                    // Include frequency sweep
    unsigned short                 LeftHander      : 1;                    // Left handed golfer
    unsigned short                 SquareAddress   : 1;                    // Force Square at address
    unsigned short                 ApplyCorrection : 1;                    // True = apply twist correction while integrating (in FREE swing mode)
    unsigned short                 QuickAnalysis   : 1;                    // True = use Quick Analysis method, else UM code
    unsigned short                 free            : 8;                    // Unused right now
} ANA_FLAGS_T;

/**
 *   ANA Parameter structure.
 *
 *   These parameters are passed into the Set ANA Mode
 *   call according to the satte the FSMis being placed in
 *
 */
typedef struct
{
    float               PitchAng;                               //<! Pitch Angle in radians
    float               PitchTol;                               //<! Pitch tolerance in radians (+/-)
    unsigned short                 PitchStab;                              //<! Pitch stable (ms)
    float               BearingAng;                             //<! Bearing in radians
    unsigned short                  BearingStab;                            //<! Bearing Stable (ms)
    float               AddressTol;                             //<! Lie Angle Tolerance in radians
    float               AddressAng;                             //<! Lie Angle in radians
    unsigned short                  AddressStab;                            //<! Address Stable (ms)
    float               PressTol;                               //<! Press tolerance in radians
    float               PressAng;                               //<! Press angle in radians
    signed short                PressStab;                              //<! Press Stable (ms)
    float               AlignTol;                               //<! Alignment Tolerance in radians
    unsigned short                 AlignStab;                              //<! Alignment Stable (ms)
    unsigned short                 ImpXTol;                                //<! Change in Acceleration on X axis for Impact detection
    unsigned short                 ImpactFinish;                           //<! Additional recording time after impact (ms)
    float               PosPlaneTolMin;                         //<! Maximum Positive Plane tolerance in radians
    float               PosPlaneTolMax;                         //<! Positive Swing Plane tolerance in radians
    float               NegPlaneTol;                            //<! Negative Swing Plane tolerance in radians
    unsigned short                 SwingCheck;                             //<! Swing Arc checkpoint (ANA_SWING_T)
    unsigned short                 MaxSwingTime;                           //<! Time allowed to complete swing in ms
    ANA_FLAGS_T         Flags;                                  //<! Specific behaviour control flags
} ANA_PARAMS_T;

// Command to set ANA mode. Note field alignment is 16-bit!
typedef struct
{
    unsigned char                  Command;                                //!< CMD_SET_PARAMS
    unsigned char                    Dummy;                                  //!< Blank
    unsigned short                   Mode;                                   //!< ANA Action to perform
    ANA_PARAMS_T        Params;                                 //!< ANA params structure
    FloatMatrix3x3_T    Matrix;
    unsigned short                   Checksum;                               //!< 16bit checksum
} CMD_SET_ANA_T;


@interface ViewController : UIViewController<NSStreamDelegate,LMComBoxViewDelegate>
@property (weak, nonatomic) IBOutlet UITextView *infoTextView;

@end
